package com.yc.txx.controller;


import com.yc.bean.Result;
import com.yc.txx.entity.TxxLease;
import com.yc.txx.entity.TxxUser;
import com.yc.txx.mapper.TxxLeaseMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;


/**
 * <p>
 * 天下行租车-用车表-10 前端控制器
 * </p>
 *
 * @author k
 * @since 2025-02-04
 */
@RestController
@RequestMapping("/txxlease")
public class TxxLeaseController {
    @Autowired
    TxxLeaseMapper txxLeaseMapper;
    //有个bug->在登录后退出再登录会导致ClassCastException
    @GetMapping("loadLeases")
    public Result loadLeases(HttpSession session) {
        TxxUser loginedUser = (TxxUser) session.getAttribute("loginedUser");
        if (loginedUser == null) {
            return new Result(-1,"未登录",null);
        }
        TxxLease[] leases = txxLeaseMapper.getLeasesByCid(loginedUser.getId());
        return new Result(1,"获取租赁记录",leases);
    }
}
